<template>
  <div>
    <van-cell>
      <div class="box">
        <div class="left">
          <van-image round fit="cover" :src="cmt.aut_photo" />
        </div>

        <div class="right">
          <p>{{ cmt.aut_name }}</p>
          <span>{{ cmt.content }}</span>
          <div class="btn">
            <span>{{ cmt.pubdate | relvTime }}</span>
          </div>
        </div>
      </div>
    </van-cell>
    <!-- 分割线 -->
    <van-divider>回复列表</van-divider>
    <!-- 下面的回复列表区域 -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.com_id">
        <div class="box">
          <div class="left">
            <van-image round fit="cover" :src="item.aut_photo" />
          </div>

          <div class="right">
            <p>{{ item.aut_name }}</p>
            <span class="content">{{ item.content }}</span>
            <div class="btn">
              <span>{{ item.pubdate | relvTime }}</span>
            </div>
          </div>
        </div>
      </van-cell>
    </van-list>
    <!-- 下面的回复发布框 -->
    <van-field
      @keyup.enter="send"
      v-model="sms"
      center
      clearable
      placeholder="请输入回复内容"
    >
      <template #button>
        <van-button @click="send" size="small" type="info">发布</van-button>
      </template>
    </van-field>
  </div>
</template>

<script>
import { cmtListApi, sendCmtApi } from '@/Api'
export default {
  props: ['cmt'],
  data () {
    return {
      sms: '',
      list: [],
      loading: false,
      finished: false
    }
  },
  methods: {
    // 发表评论回复
    async send () {
      let res = await sendCmtApi({
        target: this.cmt.com_id,
        content: this.sms,
        art_id: this.$route.query.article_id
      })
      // console.log(res)
      this.list.unshift(res.data.data.new_obj)
      this.sms = ''
      this.$toast('回复发布成功')
    },
    async onLoad () {
      let res = await cmtListApi({
        type: 'c',
        source: this.cmt.com_id
      })
      // console.log('回复', res)
      this.list.push(...res.data.data.results)
      this.finished = true
    }
  }
}
</script>

<style lang="less" scoped>
.van-list {
  margin-bottom: 54px;
}
.van-field {
  position: fixed;
  left: 0;
  bottom: 0;
}
.box {
  display: flex;
  .van-image {
    width: 60px;
    height: 60px;
  }
  .right {
    margin-left: 20px;
    font-size: 14px;
    p {
      margin-bottom: 10px;
      color: #5c7ca9;
    }

    .btn {
      span {
        font-size: 10px;
      }
      margin-top: 10px;
      color: #808080;
    }
  }
}
</style>
